using System.Collections.Generic;
using UnityEngine;

namespace Unity.Game.ElisAdvance.MonsterScript
{
    public class TestGoblinMonster
    {

        private EnemyActiveObject obj;

        public TestGoblinMonster(EnemyActiveObject active)
        {
            obj = active;
        }
        public void onInit()
        {

            obj.initActiveObjectAttackEvent();
            obj.setState(State.STATE_STAND);
            obj.getAttackInfo().setEnable(true, "PLAYER");
            obj.setTeam(Team.MONSTER);
            obj.setDirection(Direction.RIGHT);
            obj.setFilp(-1.0f);
        }
        public void onSetState(State state)
        {
            //Debug.Log("GoblinSetState" + state);
            if (state == State.STATE_ATTACK)
            {
                if (obj.getAttackIndex() == 0.0f)
                {
                    obj.getAniManager().setAni("Attack");
                }
                else if (obj.getAttackIndex() == 1.0f)
                {
                    obj.getAniManager().setAni("Attack");

                    obj.getGravityEvent().refreshGravity();
                    //obj.setXVelocity(1.0f);
                    //obj.setYVelocity(2.5f);

                    obj.getVar("initPos").clear_vector();
                    obj.getVar("initPos").push_vector(obj.getXPos());
                    obj.getVar("initPos").push_vector(obj.getYPos());
                    obj.getVar("initPos").push_vector(1.0f);
                    obj.getVar("initPos").push_vector(2.0f);

                }
            }
            else if (state == State.STATE_DAMAGE)
            {
                //obj.setShake(CameraShakeType.HORIZONTAL,1.0f, 0.2f);
            }
            else if (state == State.STATE_STAND)
            {
                obj.getAniManager().setAni("Stay");
            }
            else if (state == State.STATE_ATTACK)
            {

            }
        }

        public void onDestroy()
        {
            GameObject explosion = obj.getPool().get(0);
            //VoidWalkerDieExplosionEvent

            if (explosion)
            {
                SendActiveObjectCreatePacket sp = new SendActiveObjectCreatePacket();
                sp.startWriteFloat();
                sp.writeFloat(10);
                sp.writeFloat(10);
                sp.writeFloat(0);
                sp.writeFloat(0);
                sp.writeFloat(obj.getXPos());
                sp.writeFloat(obj.getYPos());
                sp.writeFloat(Dir.directionToNum(obj.getDirection()));
                ActiveObject exp = sp.createActiveObject(explosion, obj);
            }
        }

        public void onBeforeDestroy()
        { 
        }

        public void onDamage(ActiveObject attacker, float damage, DamageBounsType type, params float[] vector)
        {
            //Debug.Log("hitCount");

        }

        // Update is called once per frame
        public void onProc()
        {

            if (obj.getState() == State.STATE_ATTACK)
            {
                if (obj.getStateTimer() > 1.2f)
                {
                    obj.setState(State.STATE_STAND);
                }
                else
                {
                    if (obj.getStateTimer() > 0.5f && obj.getStateTimer() < 0.65f)
                    {

                        //ai.isTargetInArea(0.5f, -1.0f, 1.5f, 2.0f)
                        AttackObjectTempVector hit = obj.getAttackInfo().onInAreaAttack(0.5f, -1.0f, 1.5f, 2.0f);  
                        hit.sendHit(obj, 1.0f, DamageBounsType.PUSH, 6.0f, 3.0f,0.5f);

                    }

                    if (obj.getAttackIndex() == 1.0f)
                    {

                        /*
                        obj.getVar("initPos").clear_vector();
                        obj.getVar("initPos").push_vector(obj.getXPos());
                        obj.getVar("initPos").push_vector(obj.getTarget().getXPos());
                        */

                        float sx = obj.getVar("initPos").get_vector(0);
                        float sy = obj.getVar("initPos").get_vector(1);
                        float dash = obj.getVar("initPos").get_vector(2);
                        float jump = obj.getVar("initPos").get_vector(3);

                        float x = Com.getUnformVelocity(0, obj.getStateTimer(), 0.6f, 0.0f, dash);
                        x = Com.getDistancePos(sx, obj.getDirection(), x);
                        float y = Math2.getParabola(obj.getStateTimer(), jump, 0.6f) + sy;
                        obj.setCurrentPos(x, y);



                    }

                }
            }

            //AttackObjectTempVector hit = obj.getAttackInfo().onInAreaAttack(-0.25f, 0.0f, 0.5f, 2.0f);  
            //hit.sendHit(obj, 1.0f, DamageBounsType.PUSH, 3.0f, 2.0f,0.5f);

        }

    }

}
